import 'package:t3_data_service/biz_data_source/map/address/city_pick/model/city_pick_models.dart';
import 'package:t3_data_service/biz_data_source/map/address/poi_search/poi_search.dart';
import 'package:t3_data_service/data_provider/map_sctx/t3_map_sctx_provider.dart';
import 'package:t3_foundation/t3_foundation.dart';
import 'address_select_enums.dart';
import 'poi_search_base_config.dart';

class POISearchSinglePointConfig extends POISearchBaseConfig {
  String? placeholder;
  String? defaultText;

  factory POISearchSinglePointConfig.startNormal({T3POILocation? location}) {
    return POISearchSinglePointConfig(
      location: location,
      entryOptions: [T3EntryOptions.homeAndCompany],
      showConfusionButton: false,
      showMapSelectedFooter: false,
    );
  }

  POISearchSinglePointConfig({
    required super.location,
    super.originCoor,
    super.sceneRuleId,
    super.refererPageTitle,
    super.allowMoveOutFence = true,
    super.pointType = T3POIType.start,
    super.isUserActionDisabledForEnd = false,
    super.isUserActionDisabledForVia = false,
    super.style = T3POIStyle.normal,
    super.cityScope = CityScope.opened,
    super.showMapSelectedFooter = false,
    super.showConfusionButton = true,
    super.showBackButton = false,
    super.shouldCheckTableSelectedPoi = true,
    super.entryOptions = const [],
    super.autoOpenCitySelection = false,
    super.popUntilRoute,
    super.pageScene,
    this.placeholder,
    this.defaultText,
  });

  static POISearchSinglePointConfig fromJson(Map<dynamic, dynamic> json) {
    var config = POISearchSinglePointConfig(
      location: $T3POILocationDecode(json['location']),
      originCoor: LatLng.fromJson(json['originCoor']),
      allowMoveOutFence: BoolUtils.dynamicToBool(json['allowMoveOutFence'], true),
      pointType: T3POIType.fromJson(IntUtils.dynamicToNullInt(json['pointType'])),
      isUserActionDisabledForEnd: BoolUtils.dynamicToBool(json['isUserActionDisabledForEnd']),
      isUserActionDisabledForVia: BoolUtils.dynamicToBool(json['isUserActionDisabledForVia']),
      style: T3POIStyle.fromJson(IntUtils.dynamicToNullInt(json['style'])),
      cityScope: CityScopeExtension.initWithRawValue(IntUtils.dynamicToNullInt(json['cityScope'])) ?? CityScope.opened,
      showMapSelectedFooter: BoolUtils.dynamicToBool(json['showMapSelectedFooter']),
      showConfusionButton: BoolUtils.dynamicToBool(json['showConfusionButton'],true),
      showBackButton: BoolUtils.dynamicToBool(json['showBackButton']),
      sceneRuleId: StringUtils.dynamicToString(json['sceneRuleId']),
      refererPageTitle: StringUtils.dynamicToString(json['refererPageTitle']),
      shouldCheckTableSelectedPoi: BoolUtils.dynamicToBool(json['shouldCheckTableSelectedPoi'], true),
      entryOptions: $T3EntryOptionsEnumDecode(IntUtils.dynamicToNullInt(json['entryOptions'])),
      autoOpenCitySelection: BoolUtils.dynamicToBool(json['autoOpenCitySelection'], false),
      popUntilRoute: StringUtils.dynamicToString(json['popUntilRoute']),
      pageScene: PageScene.fromJson(json['pageScene']),
      placeholder: StringUtils.dynamicToString(json['placeholder']),
      defaultText: StringUtils.dynamicToString(json['defaultText']),
    );
    config.mapType = T3MapType.fromJson(IntUtils.dynamicToNullInt(json['mapType']));
    return config;
  }

  @override
  Map<String, dynamic> toJson() {
    var json = super.toJson();
    var newJson = {
      'placeholder': placeholder,
      'defaultText': defaultText,
    };
    for (var item in newJson.entries) {
      json[item.key] = item.value;
    }
    return json;
  }
}
